/*/////////////////////////////////////////////////////////////////////////////////
/// An
///    ___   ____ ___ _____ ___  ____
///   / _ \ / ___|_ _|_   _/ _ \|  _ \
///  | | | | |  _ | |  | || | | | |_) |
///  | |_| | |_| || |  | || |_| |  _ <
///   \___/ \____|___| |_| \___/|_| \_\
///                              File
///
/// Copyright (c) 2008-2009 Ismail TARIM <ismail@royalspor.com> and the Ogitor Team
//
//This program is free software; you can redistribute it and/or modify it under
//the terms of the GNU Lesser General Public License as published by the Free Software
//Foundation; either version 2 of the License, or (at your option) any later
//version.
//
//This program is distributed in the hope that it will be useful, but WITHOUT
//ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
//FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
//You should have received a copy of the GNU Lesser General Public License along with
//this program; if not, write to the Free Software Foundation, Inc., 59 Temple
//Place - Suite 330, Boston, MA 02111-1307, USA, or go to
//http://www.gnu.org/copyleft/lesser.txt.
////////////////////////////////////////////////////////////////////////////////*/

#pragma once

namespace Ogitors
{

class OgitorExport CNodeEditor : public CBaseEditor
{
    friend class CNodeEditorFactory;
public:
    static OgitorsPropertyDefMap propertyDefs;

    void             setPosition(const Ogre::Vector3& position, bool display);
    Ogre::Vector3    getPosition();
    void             setOrientation(const Ogre::Quaternion& orientation, bool display);
    Ogre::Quaternion getOrientation();
    void             setScale(const Ogre::Vector3& scale, bool display);
    Ogre::Vector3    getScale();
    void             setAutoTrackTarget(const Ogre::String& targetname, bool display);
    Ogre::String     getAutoTrackTarget();
    virtual void     processParameters(Ogre::NameValuePairList &params);
    virtual bool     load();
    virtual bool     unLoad();
    virtual void     attach(CBaseEditor *parent);
	virtual void     detach();
	virtual void     getObjectProperties(Ogre::NameValuePairList &retList);
	virtual bool	 setupPropertiesWnd(bool present);
	virtual void     showBoundingBox(bool bShow);


	virtual bool            isNodeType() {return true;};

	/// This function is called when user right clicks a property to get that property specific popup menu
	/// returns false if no menu present (Disabled Menu Items has a "D" prefix where Enabled Menu Items have "E" prefix
	virtual bool                 getObjectContextMenu(UTFStringVector &menuitems);
    /// This function is called when user selects a menuitem from ContextMenu
	virtual void                 onObjectContextMenu(int menuresult);
	/// General Purpose Update Function Used By OgitorsRoot Override for Descendants
	virtual bool                 postSceneUpdate(Ogre::SceneManager *SceneMngr, Ogre::Camera *Camera, Ogre::RenderWindow *RenderWindow);
    /// Overridden by Editor Objects to Import Object Dependant Properties
    virtual void                 restore(Ogre::NameValuePairList &retList);
    /// Gets the Handle to encapsulated object
    inline virtual void         *getHandle() {return static_cast<void*>(m_Handle);};
    /// Returns the Factory associated with this object
	static CBaseEditorFactory   *getFactory();
    /// Returns the Factory associated with this object can be overridden
	virtual CBaseEditorFactory  *getFactoryDynamic();
	virtual Ogre::Vector3	     getDerivedPosition();
	virtual Ogre::Quaternion     getDerivedOrientation();
	virtual Ogre::Vector3        getDerivedScale();
    virtual Ogre::AxisAlignedBox getAABB() {if(m_Handle) return m_Handle->_getWorldAABB();else return Ogre::AxisAlignedBox::BOX_NULL;};
	virtual Ogre::SceneNode     *getNode() {return m_Handle;};
	virtual Ogre::SceneManager  *getSceneManager() {return m_Handle->getCreator();};

protected:
	Ogre::SceneNode *m_Handle;
    Ogre::String     m_AutoTrackTarget;
    Ogre::Vector3    m_Position;
    Ogre::Vector3    m_Scale;
    Ogre::Quaternion m_Orientation;
    CBaseEditor     *m_AutoTrackTargetPtr;
    OgitorsScopedConnection m_AutoTrackTargetConnection[3];
    
	CNodeEditor();
	virtual     ~CNodeEditor();

    /// Auto Track Target Observation Related
    void OnTrackTargetDestroyed(Ogre::Any value);
    void OnTrackTargetPositionChange(Ogre::Any value);
    void OnTrackTargetNameChange(Ogre::Any value);
};

class OgitorExport CNodeEditorFactory: public CBaseEditorFactory
{
public:
  CNodeEditorFactory();
  virtual ~CNodeEditorFactory() {};
  virtual void Init();
  virtual CBaseEditor *CreateObject(CBaseEditor **parent, Ogre::NameValuePairList &params);
  virtual Ogre::String GetPlaceHolderName() {return "scbLight_Omni.mesh";};
};
}

